package cn.innosmart.aq.manager;

import com.tutk.p2p.ConnectionEntity;
import com.tutk.p2p.ResponseHandler;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by David on 2016/2/2.
 */
public class P2PTunnelManager extends BaseManager {

    private P2PTunnelManager() {

    }

    public static P2PTunnelManager getInstance() {
        return P2PTunnelManagerInstance.instance;
    }

    /**
     * 远程启动AQ里面的P2P用于调试
     *
     * @param connectionEntity
     * @return
     */
    public boolean sendTest(ConnectionEntity connectionEntity) {
        long callid = System.currentTimeMillis() / 1000 + 1;
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mP2PTunelCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        JSONObject jsonParams = new JSONObject();
        try {
            jsonParams.put("UID", "WRF64FY3P5A1M2D3111A");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "P2PTunnelManager.StartP2PTunnelServer", jsonParams.toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    private ResponseHandler.ResponseCallback mP2PTunelCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
        }
    };

    private static class P2PTunnelManagerInstance {
        private static final P2PTunnelManager instance = new P2PTunnelManager();
    }

}
